package org.example.project.search.data

/**
 * 检索sug
 * Created by abqiu on 2017/6/28.
 */
class Suggestion {
    /**
     * 数据请求id，统计使用
     */
    var requestId: String? = null

    /**
     * 数据id
     */
    var id: String? = null

    /**
     * 名称
     */
    var name: String? = null

    /**
     * 子点上展示的名字（主点同name）
     */
    var showName: String? = null

    /**
     * 经纬度
     */
    var latLng: LatLng? = null

    /**
     * sug类型
     */
    var type: Long = 0

    /**
     * 用来区分美食和酒店
     */
    var coType: Int = 0

    /**
     * 类别词
     */
    var typeWord: String? = null

    /**
     * 距离
     */
    var distance: String? = null

    /**
     * 距离类型，供h5页面使用
     * 0:只显示米/公里（预留字段)
     * 1:距你
     * 2:距查询位置
     */
    var distanceType: Int = 1

    /**
     * 途经线路
     */
    var sgPassLines: List<SgPassLine>? = null

    /**
     * 地址
     */
    var address: String? = null

    /**
     * 评分，100分满分
     */
    var starLevel: Int = 0

    /**
     * 到访人数
     */
    var arrival: String? = null

    /**
     * 实时人气信息
     */
    var behavior: String? = null

    /**
     * 人流密度信息
     */
    var peopleFlow: String? = null

    /**
     * 子点
     */
    var subSuggestions: List<Suggestion>? = null

    /**
     * 是否为离线数据
     */
    var isOfflineData: Boolean = false

    /**
     * 是否显示sug列表item混淆提示
     */
    var showSugItemConfusionTips: Boolean = false

    /**
     * sug城市
     */
    var city: String? = null

    /**
     * 区划
     */
    var area: String? = null

    /**
     * 来源（用于记录外部跳转添加到历史记录）
     */
    var fromSource: Int = 0

    /**
     * fromSource
     */
    var fromSourceStr: String? = null

    /**
     * index(统计使用 该索引值从1开始)
     */
    var index: Int = 1

    /**
     * city index(统计使用 该索引值从1开始)
     */
    var cityIndex: Int = 1

    /**
     * 实时公交信息
     */
    var realtime: BusRealtimeInfo? = null

    /**
     * 区域码
     */
    var nSO: Long = 0

    /**
     * 分类码
     */
    var nCO: Long = 0

    /**
     * 建筑物id
     */
    var building_id: String? = null

    /**
     * 室内id
     */
    var shinei_id: String? = null

    /**
     * 楼层id
     */
    var floor_id: String? = null

    /**
     * 楼层名称
     */
    var floor_name: String? = null

    /**
     * POI信息
     */
    var poiErrInfo: String? = null

    /**
     * POI信息颜色
     */
    var nplColor: String? = null

    /**
     * POI标签
     */
    var reviewTag: List<RichReviewTag>? = null

    /**
     * 区划类型
     */
    var districtType: Int = 0

    /**
     * 城市聚合类型中的suggestion
     */
    var suggestionsInCity: List<Suggestion>? = null

    /**
     * 城市聚合中的城市名称
     *
     * @return
     */
    var cityName: String? = null

    /**
     * 城市聚合中需要展示的城市数
     */
    var folderNumer: Int = 0

    /**
     * 城市聚合中，展示的城市数据
     */
    var showPoiCount: Int = 0

    /**
     * 直达信息
     */
    var searchdirect: SearchDirect? = null


    /**
     * 短地址
     */
    var shortAddress: String? = null

    /**
     * 头图url,特型结果生效
     */
    var picUrl: String = ""

    /**
     * 召回排序标签
     */
    var recallTag: List<RichReviewTag>? = null

    /**
     * 当为"1"时，展示具体距离，当为"0"时，展示"去这里"
     * 手图兜底策略，为其他值时展示距离
     */
    var showDis: String? = null

    /**
     * 和人气热度字段"heat_info(strAccess)"二者只
     * 会出现一个，出现"heat_info"时展示
     * 人气热度，出现"price_info"时展示人均价格
     */
    var priceInfo: String? = null

    /**
     * 小程序icons
     */
    var icons: List<richTag>? = null

    /**
     * 子点的概率值
     */
    var subSugProb: Float = 0f

    /**
     * 子点的概率颜色
     */
    var subSugProbColor: String? = null

    /**
     * 小程序信息
     */
    var miniApp: MiniApp? = null

    /**
     * 插入文案的数据
     */
    var hintData: SuggestionHintData? = null

    /**
     * 尾部的文本
     */
    var footerText: String? = null

    /**
     * 混淆的文本
     */
    var sugConfusionText: String? = null

    /**
     * 是否是经纬度搜索的附近地点
     */
    var isLatLngSearchNear: Boolean = false

    /**
     * 尾部的跳转链接
     */
    var footerJumpUrl: String? = null

    var labelType: String? = null

    var labelTextColor: String? = null

    var labelStrokeColor: String? = null

    var themeTipInfo: ThemeTipInfo? = null

    /**
     * 高亮频率，单飘or多飘
     */
    var highLightFreq: Int = HIGHLIGHT_FIRST

    /**
     * 高亮位置的list
     */
    var highlightPositions: HashMap<Int, String>? = null

    /**
     * 高亮的文本内容
     */
    var highlightText: String? = null

    /**
     * 城市短名
     */
    var shortCityName: String? = null

    var aliasTypeStr: String? = null

    var aliasName: String? = null

    var additionalInfo: Map<String, String>? = null

    var title: TipsInfo? = null

    var detail: TipsInfo? = null

    var look: TipsInfo? = null

    var sign: SignInfo? = null

    var poiInfoUrl: String? = null

    var poiInfoType: String? = null

    var poiInfoTag: String? = null

    /**
     * 猜你想搜和主子词-带 icon
     */
    var guessInfo: sugGuessInfo? = null

//    val sugJumpInfoData: SugJumpInfoData?
//        get() {
//            if (title == null) {
//                return null
//            }
//            val infoData: SugJumpInfoData = SugJumpInfoData()
//            infoData.requestId = requestId
//            infoData.name = name
//            infoData.keyword = highlightText
//            infoData.title = title
//            infoData.detail = detail
//            infoData.look = look
//            infoData.sign = sign
//            infoData.poiInfoUrl = poiInfoUrl
//            infoData.poiInfoTag = poiInfoTag
//            infoData.poiInfoType = poiInfoType
//            return infoData
//        }

    val searchName: String?
        /**
         * 获取搜索词
         *
         * @return
         */
        get() = if (!name.isNullOrBlank()) {
            name
        } else {
            showName
        }

//    fun getFromSourceStr(context: android.content.Context?): String {
//        if (context == null) {
//            return ""
//        }
//        var fromSourceStr = ""
//        when (fromSource) {
//            FROM_SOURCE_DEFAULT -> {}
//            FROM_SOURCE_WEIXIN -> fromSourceStr =
//                context.getResources().getString(R.string.map_poi_from_source_weixin)
//
//            FROM_SOURCE_QQ -> fromSourceStr =
//                context.getResources().getString(R.string.map_poi_from_source_qq)
//
//            FROM_SOURCE_QQ_BROWSER -> fromSourceStr =
//                context.getResources().getString(R.string.map_poi_from_source_qq_browser)
//
//            FROM_SOURCE_OTHER, FROM_SOURCE_MIGRATE -> fromSourceStr =
//                context.getResources().getString(R.string.map_poi_from_source_other)
//
//            FROM_SOURCE_QQMINI -> fromSourceStr =
//                context.getResources().getString(R.string.map_poi_from_source_qq)
//
//            else -> {}
//        }
//        return fromSourceStr
//    }

//    val isFromExternalSource: Boolean
//        /**
//         * 是否来自外部跳转
//         *
//         * @return
//         */
//        get() {
//            if (!android.text.TextUtils.isEmpty(fromSourceStr)) {
//                fromSource = fromSourceExtra(FromSource.parserAction(fromSourceStr))
//                //优先使用fromSourceStr判定
//                if ("EXTRA".equals(FromSource.parserCategory(fromSourceStr), ignoreCase = true)) {
//                    return true
//                }
//            }
//            return fromSource == FROM_SOURCE_WEIXIN || fromSource == FROM_SOURCE_QQ || fromSource == FROM_SOURCE_QQ_BROWSER || fromSource == FROM_SOURCE_OTHER || fromSource == FROM_SOURCE_MIGRATE || fromSource == FROM_SOURCE_QQMINI
//        }
//
//    fun setFromSourceStr(fromSourceStr: String?) {
//        if (android.text.TextUtils.isEmpty(this.fromSourceStr)) {
//            this.fromSourceStr = fromSourceStr
//        }
//    }

    val miniAppName: String
        get() = miniApp?.app_name ?: ""

    val miniAppHType: Int
        get() = miniApp?.h_type ?: 1

    val guessInfoHType: Int
        get() = if (guessInfo != null) guessInfo!!.h_type!! else 1

    constructor(
        name: String? = null,
        requestId: String? = null,
        id: String? = null,
        showName: String? = null,
        latLng: LatLng? = null,
        type: Long = 0,
        coType: Int = 0,
        typeWord: String? = null,
        distance: String? = null,
        distanceType: Int = 0,
        sgPassLines: List<SgPassLine>? = null,
        address: String? = null,
        starLevel: Int = 0,
        arrival: String? = null,
        behavior: String? = null,
        peopleFlow: String? = null,
        subSuggestions: List<Suggestion>? = null,
        isOfflineData: Boolean = false,
        showSugItemConfusionTips: Boolean = false,
        city: String? = null,
        area: String? = null,
        fromSource: Int = 0,
        fromSourceStr: String? = null,
        index: Int = 0,
        cityIndex: Int = 0,
        realtime: BusRealtimeInfo? = null,
        nSO: Long = 0,
        nCO: Long = 0,
        building_id: String? = null,
        shinei_id: String? = null,
        floor_id: String? = null,
        floor_name: String? = null,
        poiErrInfo: String? = null,
        nplColor: String? = null,
        reviewTag: List<RichReviewTag>? = null,
        districtType: Int = 0,
        suggestionsInCity: List<Suggestion>? = null,
        cityName: String? = null,
        folderNumer: Int = 0,
        showPoiCount: Int = 0,
        searchdirect: SearchDirect? = null,
        shortAddress: String? = null,
        picUrl: String = "",
        recallTag: List<RichReviewTag>? = null,
        showDis: String? = null,
        priceInfo: String? = null,
        icons: List<richTag>? = null,
        subSugProb: Float = 0f,
        subSugProbColor: String? = null,
        miniApp: MiniApp? = null,
        hintData: SuggestionHintData? = null,
        footerText: String? = null,
        sugConfusionText: String? = null,
        isLatLngSearchNear: Boolean = false,
        footerJumpUrl: String? = null,
        labelType: String? = null,
        labelTextColor: String? = null,
        labelStrokeColor: String? = null,
        themeTipInfo: ThemeTipInfo? = null,
        highLightFreq: Int = HIGHLIGHT_FIRST,
        highlightPositions: HashMap<Int, String>? = null,
        highlightText: String? = null,
        shortCityName: String? = null,
        aliasTypeStr: String? = null,
        aliasName: String? = null,
        additionalInfo: Map<String, String>? = null,
        title: TipsInfo? = null,
        detail: TipsInfo? = null,
        look: TipsInfo? = null,
        sign: SignInfo? = null,
        poiInfoUrl: String? = null,
        poiInfoType: String? = null,
        poiInfoTag: String? = null,
        guessInfo: sugGuessInfo? = null
    ) {
        this.name = name
        this.requestId = requestId
        this.id = id
        this.showName = showName
        this.latLng = latLng
        this.type = type
        this.coType = coType
        this.typeWord = typeWord
        this.distance = distance
        this.distanceType = distanceType
        this.sgPassLines = sgPassLines
        this.address = address
        this.starLevel = starLevel
        this.arrival = arrival
        this.behavior = behavior
        this.peopleFlow = peopleFlow
        this.subSuggestions = subSuggestions
        this.isOfflineData = isOfflineData
        this.showSugItemConfusionTips = showSugItemConfusionTips
        this.city = city
        this.area = area
        this.fromSource = fromSource
        this.fromSourceStr = fromSourceStr
        this.index = index
        this.cityIndex = cityIndex
        this.realtime = realtime
        this.nSO = nSO
        this.nCO = nCO
        this.building_id = building_id
        this.shinei_id = shinei_id
        this.floor_id = floor_id
        this.floor_name = floor_name
        this.poiErrInfo = poiErrInfo
        this.nplColor = nplColor
        this.reviewTag = reviewTag
        this.districtType = districtType
        this.suggestionsInCity = suggestionsInCity
        this.cityName = cityName
        this.folderNumer = folderNumer
        this.showPoiCount = showPoiCount
        this.searchdirect = searchdirect
        this.shortAddress = shortAddress
        this.picUrl = picUrl
        this.recallTag = recallTag
        this.showDis = showDis
        this.priceInfo = priceInfo
        this.icons = icons
        this.subSugProb = subSugProb
        this.subSugProbColor = subSugProbColor
        this.miniApp = miniApp
        this.hintData = hintData
        this.footerText = footerText
        this.sugConfusionText = sugConfusionText
        this.isLatLngSearchNear = isLatLngSearchNear
        this.footerJumpUrl = footerJumpUrl
        this.labelType = labelType
        this.labelTextColor = labelTextColor
        this.labelStrokeColor = labelStrokeColor
        this.themeTipInfo = themeTipInfo
        this.highLightFreq = highLightFreq
        this.highlightPositions = highlightPositions
        this.highlightText = highlightText
        this.shortCityName = shortCityName
        this.aliasTypeStr = aliasTypeStr
        this.aliasName = aliasName
        this.additionalInfo = additionalInfo
        this.title = title
        this.detail = detail
        this.look = look
        this.sign = sign
        this.poiInfoUrl = poiInfoUrl
        this.poiInfoType = poiInfoType
        this.poiInfoTag = poiInfoTag
        this.guessInfo = guessInfo
    }

    override fun equals(o: Any?): Boolean {
        if (o !is Suggestion) {
            return false
        }
        val suggestionComp = o
        return this === suggestionComp || ((this.id.isNullOrEmpty() && this.id == suggestionComp.id)
                || isStringEqual(this.name, suggestionComp.name) && isStringEqual(
            this.address,
            suggestionComp.address
        ))
                && this.fromSource == suggestionComp.fromSource
    }

    override fun hashCode(): Int {
        val array = arrayOf<Any?>(this.name, this.address, this.fromSource)
        return array.contentHashCode()
    }

    private fun isStringEqual(s1: String?, s2: String?): Boolean {
        if (s1.isNullOrEmpty()) {
            return s2.isNullOrBlank()
        }
        return s1 == s2
    }

    companion object {
        /**
         * sug混淆提示类型
         */
        const val TYPE_SUG_CONFUSION_TIPS: Int = -10

        /**
         * 底栏，显示查看更多
         */
        const val TYPE_FOOTER: Int = 10

        /**
         * poi类型
         */
        const val TYPE_POI: Int = 11

        /**
         * 城市名
         */
        const val TYPE_CITY: Int = 12

        /**
         * 类别词
         */
        const val TYPE_CATEGORY: Int = 13

        /**
         * 标签词
         */
        const val TYPE_TAG: Int = 14

        /**
         * 连锁店
         */
        const val TYPE_CHAIN_STORE: Int = 15

        /**
         * 门牌地址
         */
        const val TYPE_DOORPLATE: Int = 16

        /**
         * 搜索直达
         */
        const val TYPE_SEARCH_DIRECT: Int = 17

        /**
         * 小程序入口
         */
        const val TYPE_MINI_APP: Int = 18

        /**
         * 主子提示词 带 icon- 双行样式
         */
        const val TYPE_SUB_WORD_ICON: Int = 19

        /**
         * 主子提示词 带 icon-  单行样式
         */
        const val TYPE_SUB_WORD_ICON_SINGLE_LINE: Int = 1019

        /**
         * 猜你想搜
         */
        const val TYPE_GUESS: Int = 20

        /**
         * 提示条
         */
        const val TYPE_TIP1: Int = 25
        const val TYPE_TIP2: Int = 26
        const val TYPE_TIP3: Int = 27

        /**
         * 地铁站
         */
        const val TYPE_METRO_STATION: Int = 21

        /**
         * 地铁线路
         */
        const val TYPE_METRO_LINE: Int = 22

        /**
         * 公交线路
         */
        const val TYPE_BUS_LINE: Int = 24

        /**
         * 公交站
         */
        const val TYPE_BUS_STATION: Int = 23

        /**
         * AIChat
         */
        const val TYPE_AI_CHAT: Int = 28

        /**
         * 坐标搜索
         */
        const val TYPE_LATLNG_SEARCH: Int = 29

        /**
         * 城市聚合Footer
         */
        const val TYPE_MERGED_CITY_FOOTER: Int = 31


        /**
         * 带地址单行（用于城市聚合）
         */
        const val TYPE_SINGLE_LINE: Int = 32

        /**
         * 城市页卡类型
         */
        const val TYPE_CITYCARD: Int = 1001

        /**
         * 城市聚合类型
         */
        const val TYPE_MERGED_CITY: Int = 1002

        /**
         * 城市定位锚点
         */
        const val TYPE_CITY_ANCHOR: Int = -2


        const val TYPE_HINT: Int = -1

        const val TYPE_ADD_LOCATION: Int = -10000

        /**
         * 默认来源
         */
        const val FROM_SOURCE_DEFAULT: Int = 0

        /**
         * 外部跳转来源-微信
         */
        const val FROM_SOURCE_WEIXIN: Int = 1

        /**
         * 外部跳转来源-QQ
         */
        const val FROM_SOURCE_QQ: Int = 2

        /**
         * 外部跳转来源-QQ浏览器
         */
        const val FROM_SOURCE_QQ_BROWSER: Int = 3

        /**
         * 外部跳转-其他来源
         */
        const val FROM_SOURCE_OTHER: Int = 4

        /**
         * 外部跳转-旧数据库合并来源
         */
        const val FROM_SOURCE_MIGRATE: Int = 5

        /**
         * 外部跳转来源-qqmini
         */
        const val FROM_SOURCE_QQMINI: Int = 6

        const val SHOW_DISTANCE: String = "1"

        /**
         * 仅高亮首个匹配文本
         */
        const val HIGHLIGHT_FIRST: Int = 1

        /**
         * 高亮全部匹配文本
         */
        const val HIGHLIGHT_ALL: Int = 2

        /**
         * 高亮位置——主名称
         */
        const val HIGHLIGHT_POS_NAME: Int = 1

        /**
         * 高亮位置——类别
         */
        const val HIGHLIGHT_POS_CLASS: Int = 2

        /**
         * 高亮位置——地址
         */
        const val HIGHLIGHT_POS_ADDRESS: Int = 3

        /**
         * 高亮位置——别名
         */
        const val HIGHLIGHT_POS_ALIAS: Int = 4


        /**
         * 城市锚点栏存在
         */
        const val CITY_BAR_EXIST: Int = 1

        /**
         * 城市锚点栏最多城市数量
         */
        const val CITY_BAR_MAX_CITY_NUM: Int = 4
        const val OTHER_CITY_STR: String = "其他城市"
        const val OTHER_CITIES: String = "others"

//        fun fromSourceStrbyType(type: Long): String {
//            return when (type.toInt()) {
//                FROM_SOURCE_WEIXIN -> "extra_poi_wx"
//                FROM_SOURCE_QQ -> "extra_poi_qq"
//                FROM_SOURCE_QQ_BROWSER -> "extra_poi_qq_browser"
//                FROM_SOURCE_OTHER -> "extra_poi_other"
//                FROM_SOURCE_MIGRATE -> "extra_local_migrate"
//                FROM_SOURCE_QQMINI -> "extra_poi_qqmini"
//                else -> FromSource.builder()
//                    .categroy(FromSource.Category.poi)
//                    .page(FromSource.Page.local)
//                    .action(FromSource.Action.loaction).toString()
//            }
//        }

        private fun fromSourceExtra(action: String): Int {
            return if (action.isBlank()) {
                FROM_SOURCE_DEFAULT
            } else if ("WX".equals(action, ignoreCase = true)) {
                FROM_SOURCE_WEIXIN
            } else if ("QQ".equals(action, ignoreCase = true)) {
                FROM_SOURCE_QQ
            } else if ("QQBROWSER".equals(action, ignoreCase = true)) {
                FROM_SOURCE_QQ_BROWSER
            } else if ("OTHER".equals(action, ignoreCase = true)) {
                FROM_SOURCE_OTHER
            } else if ("MIGRATE".equals(action, ignoreCase = true)) {
                FROM_SOURCE_MIGRATE
            } else if ("QQMINI".equals(action, ignoreCase = true)) {
                FROM_SOURCE_QQMINI
            } else {
                FROM_SOURCE_DEFAULT
            }
        }
    }
}
